define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
	function get_need_number(){
		$.post("qingdongams/customer/need/get_need_number",function (data){
			top.window.Backend.api.sidebar({
				'qingdongams/customer/need/index':[data.data.number, 'red', 'badge'],
				'qingdongams/customer/need':[data.data.number, 'red', 'badge'],
				'qingdongams/examine/examine/achievement':[data.data.achievement, 'red', 'badge'],
				'qingdongams/examine/examine/index':[data.data.contract, 'red', 'badge'],
				'qingdongams/examine/examine/consume':[data.data.consume, 'red', 'badge'],
				'qingdongams/examine/examine/receivables':[data.data.receivables, 'red', 'badge'],
				'qingdongams/examine/examine/quote':[data.data.quote, 'red', 'badge'],
				'qingdongams/examine/examine/parts':[data.data.parts, 'red', 'badge'],
				'qingdongams/examine/examine/work':[data.data.approval, 'red', 'badge'],
				'qingdongams/workorder/workorder/index':[data.data.workorder, 'red', 'badge'],
				'qingdongams/examine/examine/invoice':[data.data.invoice, 'red', 'badge'],
			});
		},'json');
	}
	get_need_number();
	var Controller = {
		index  : function () {
			// 初始化表格参数配置
			Table.api.init({
				extend : {
					index_url  : 'qingdongams/workorder/workorder/index',
					detail_url : 'qingdongams/workorder/workorder/detail',
					multi_url  : 'qingdongams/workorder/workorder/multi',
					table      : 'workorder',
				}
			});

			var table = $("#table");

			// 初始化表格
			table.bootstrapTable({
				url          : $.fn.bootstrapTable.defaults.extend.index_url+'?createtime='+Fast.api.query("createtime")+'&need='+Fast.api.query("need"),
				pk           : 'id',
				sortName     : 'id',
				fixedColumns : true,
				fixedNumber  : 2,
				columns      : [
					[
						{field: 'workorder_number', title: '工单编号', operate: 'like'},
						{
							field: 'title', title: '工单标题', fixedColumns: true, formatter: function (value, row, index) {

								return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-detail'>" + value + "</a>";
							}, operate: 'like'
						},
						{field: 'workorder_type', title: '工单类型', operate: 'like'},
						{
							field: 'status', title: '工单状态', formatter: Table.api.formatter.status,
							searchList: { 1: '待处理', 2: '处理中', 3: '已完成',9:"已撤销"}
						},
						{
							field: 'process', title: '工单进程', formatter: Table.api.formatter.status,
							searchList: {0: '已提交', 1: '备货中', 2: '备货完成', 3: '到访/录入物流信息',4:"已完成",5:"待录入物流信息",7:"费用待审核", 9: '已送达'}
						},

						{field : 'customer', title : '客户名称', formatter : function (value, row, index) {
								if(!value){
									return '';
								}
								return "<a href='javascript:void(0);' data-id='" + row.customer_id + "' class='show-customer'>" + value.name + "</a>";
							},operate:false},
						{field: 'contacts', title: '联系人', formatter : function (value, row, index) {
								if(!value){
									return '';
								}
								return value.name ;
							},operate:false},
						{field: 'createtime', title: '创建时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.date},
						{field: 'end_time', title: '结束时间', operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
						{field: 'results', title: '结果说明', operate: false},
					]
				],
				pagination        : true,
				search            : false,
				commonSearch      : true,
				searchFormVisible : true,
				//显示导出按钮
				showExport: false,
				onLoadSuccess:function(){

				}
			});
			$(document).on('click', '.show-detail', function (data) {
				var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
				var options = {
					shadeClose : false,
					shade      : [0.3, '#393D49'],
					area       : area,
					callback   : function (value) {
						//在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
						console.log(value);
					}
				};
				Fast.api.open($.fn.bootstrapTable.defaults.extend.detail_url + "?ids=" + $(this).data('id'), '工单详情', options);
			});
			$(document).on('click', '.show-customer', function (data) {
				var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
				var options = {
					shadeClose : false,
					shade      : [0.3, '#393D49'],
					area       : area,
					callback   : function (value) {
						//在回调函数里可以调用你的业务代码实现前端的各种逻辑和效果
						console.log(value);
					}
				};
				Fast.api.open("qingdongams/customer/customer/detail?ids=" + $(this).data('id'), '客户详情', options);
			});

			// 为表格绑定事件
			Table.api.bindevent(table);
		},
		add    : function () {
			Controller.api.bindevent();
		},
		edit    : function () {
			Controller.api.bindevent();
		},
		change    : function () {
			Controller.api.bindevent();
		},
		batch_change    : function () {
			Controller.api.bindevent();
		},
		transfer    : function () {
			Controller.api.bindevent();
		},
		complete    : function () {
			Controller.api.bindevent();
		},
		add_log    : function () {
			Controller.api.bindevent();
		},
		receipt    : function () {
			Controller.api.bindevent();
		},
		add_events    : function () {
			Controller.api.bindevent();
		},
		cancel_workorder    : function () {
			Controller.api.bindevent();
		},
		add_logistics    : function () {
			$(document).on('change','[name="row[type]"]',function (){
				var type=$(this).val();
				if(type == '物流配送'){
					$('#songhuo').hide();
					$('#wuliu').show();
				}else{
					$('#songhuo').show();
					$('#wuliu').hide();
				}
			})
			Controller.api.bindevent();
		},
		edit_logistics    : function () {
			$(document).on('change','[name="row[type]"]',function (){
				var type=$(this).val();
				if(type == '物流配送'){
					$('#songhuo').hide();
					$('#wuliu').show();
				}else{
					$('#songhuo').show();
					$('#wuliu').hide();
				}
			})
			Controller.api.bindevent();
		},

		detail : function () {

			// 初始化表格参数配置
			Table.api.init({});
			// quote
			var ids = $('#ids').val()
			var tablejoint_follow = $("#table-joint_follow");
			tablejoint_follow.bootstrapTable({
				url          : 'qingdongams/workorder/workorder/getShowStaff?ids=' + ids,
				pk           : 'id',
				sortName     : 'id',
				operate      : false,
				commonSearch : false,
				search       : false,
				visible      : false,
				showColumns  : false,
				showExport   : false,
				showToggle   : false,
				columns      : [
					[
						{field : 'staff.img', title : '头像', formatter: Table.api.formatter.image},
						{field : 'staff.name', title : '员工姓名'},
						{field : 'staff.mobile', title : '员工电话'},
						{field : 'staff.post', title : '员工角色'},
						{field : 'roles', title : '团队角色'},
						{field : 'is_edit', title : '权限'},
					]
				]
			});

			//费用
			var table5 = $("#consume");
			table5.bootstrapTable({
				url          : 'qingdongams/workorder/workorder/get_consume' + location.search,
				pk           : 'id',
				sortName     : 'id',
				toolbar: '#consume_toolbar',
				operate      : false,
				commonSearch : false,
				search       : false,
				visible      : false,
				showColumns  : false,
				showExport   : false,
				showToggle   : false,
				columns      : [
					[
						{field : 'createtime', title : '提交日期'},
						{field: 'number',title: '费用编号',fixedColumns: true,operate: 'like',
							formatter: function (value, row, index) {
								if (row.number == null) {
									return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-consume-detail'>无</a>";
								} else {
									return "<a href='javascript:void(0);' data-id='" + row.id + "' class='show-consume-detail '>" + row.number + "</a>";
								}

							},

						},
						{field : 'title_text', title : '费用类型'},
						{field : 'money', title : '消费金额'},
						{field : 'staff.name', title : '消费人'},

						{field : 'check_status', title : '状态', formatter : Table.api.formatter.status,
							searchList : {0 : '待审核', 1 : '审核中', 2 : '审核通过', 3 : '审核未通过', 4 : '撤销', 5 : '草稿(未提交)'},operate:false},
					]
				]
			});

			// 为表格绑定事件
			Table.api.bindevent(table5);
			$(document).on('click','.btn-set_team',function () {
				var id=$('#ids').val();
				Fast.api.open("qingdongams/workorder/workorder/set_team?ids="+id, "团队修改",{
					shadeClose: false,
					shade: false,
					maxmin: false,
					moveOut: false,
					scrollbars:false,
					area:["90%","90%"],
					callback:function () {
						location.reload();
					}
				});
			}).on('click', '.show-consume-detail', function () {
				var id = $(this).data('id');
				var area = [$(window).width() > 1200 ? '1200px' : '95%', $(window).height() > 800 ? '800px' : '95%'];
				var options = {
					shadeClose: false,
					shade: [0.3, '#393D49'],
					area: area,
				};
				Fast.api.open("qingdongams/customer/consume/detail?ids=" + id, '费用详情', options);
			});
			$(document).on('click','.btn-design-success',function () {

				Fast.api.open("qingdongams/workorder/workorder/complete?ids="+Config.idinfo.id,
					"设计成功",{
					shadeClose: false,
					shade: false,
					maxmin: false,
					moveOut: false,
					scrollbars:false,
					'area':[
						$(window).width() > 800 ? '600px' : '400px',
						$(window).height() > 600 ? '500px' : '400px'
					],
					callback:function(value){
						location.reload();
					},
				});

			}).on('click','.btn-design-error',function () {

				Fast.api.open("qingdongams/workorder/workorder/fail_workorder?ids="+Config.idinfo.id,
					"设计失败",{
					shadeClose: false,
					shade: false,
					maxmin: false,
					moveOut: false,
					scrollbars:false,
					'area':[
						$(window).width() > 800 ? '600px' : '400px',
						$(window).height() > 600 ? '500px' : '400px'
					],
					callback:function(value){
						location.reload();
					},
				});

			}).on('click','.btn-cancel',function () {

				Fast.api.open("qingdongams/workorder/workorder/cancel_workorder?ids="+Config.idinfo.id,
					"终止工单",{
					shadeClose: false,
					shade: false,
					maxmin: false,
					moveOut: false,
					scrollbars:false,
					'area':[
						$(window).width() > 800 ? '600px' : '400px',
						$(window).height() > 600 ? '500px' : '400px'
					],
					callback:function(value){
						location.reload();
					},
				});

			}).on('click','.btn-change',function () {

				Fast.api.open("qingdongams/workorder/workorder/transfer?ids="+Config.idinfo.id,
					"转派工单",{
					shadeClose: false,
					shade: false,
					maxmin: false,
					moveOut: false,
					scrollbars:false,
					'area':[
						$(window).width() > 800 ? '600px' : '400px',
						$(window).height() > 600 ? '500px' : '400px'
					],
					callback:function(value){
						location.reload();
					},
				});

			}).on('click','.btn-add-log',function () {

				Fast.api.open("qingdongams/workorder/workorder/add_log?ids="+Config.idinfo.id,
					"新建跟进",{
					shadeClose: false,
					shade: false,
					maxmin: false,
					moveOut: false,
					scrollbars:false,
					'area':[
						$(window).width() > 800 ? '600px' : '400px',
						$(window).height() > 600 ? '500px' : '400px'
					],
					callback:function(value){
						location.reload();

					},
				});

			}).on('click','.btn-accept',function () {
				Layer.confirm('确定要接受工单吗？', {
					btn: ['确定','取消'],
					title: '提示',
				},function(index, layero){
					Fast.api.ajax("qingdongams/workorder/workorder/accept_order?ids="+Config.idinfo.id,function(data,ret){
						if(ret.code == 1){
							Layer.close(index);
							location.reload();
						}
					},function(data,ret){
					});
				});
			}).on('click','.btn-product-number',function () {

				Fast.api.open("qingdongams/workorder/workorder/set_customer_product_number?ids="+Config.idinfo.id,
					"填写配送信息",{
						shadeClose: false,
						shade: false,
						maxmin: false,
						moveOut: false,
						scrollbars:false,
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
							location.reload();
						},
					});

			}).on('click','.btn-add-logistics',function () {

				Fast.api.open("qingdongams/workorder/workorder/add_logistics?ids="+Config.idinfo.id,
					"填写物流信息",{
						shadeClose: false,
						shade: false,
						maxmin: false,
						moveOut: false,
						scrollbars:false,
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
							location.reload();
						},
					});

			}).on('click','.btn-edit-logistics',function () {
				var lid=$(this).data('id');
				Fast.api.open("qingdongams/workorder/workorder/edit_logistics?ids="+lid,
					"编辑物流信息",{
						shadeClose: false,
						shade: false,
						maxmin: false,
						moveOut: false,
						scrollbars:false,
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
							location.reload();
						},
					});

			}).on('click','.btn-complete',function () {
				Layer.confirm('确定要已全部到货吗？', {
					btn: ['确定','取消'],
					title: '提示',
				},function(index, layero){
					Fast.api.ajax({
						url: "qingdongams/workorder/workorder/complete?ids="+Config.idinfo.id,
						data: {row: {id:Config.idinfo.id}},
					},function(data,ret){
						if(ret.code == 1){
							Layer.close(index);
							location.reload();
						}
					},function(data,ret){
					});
				});
			}).on('click','.btn-receipt',function () {
				Fast.api.open("qingdongams/workorder/workorder/receipt?ids="+Config.idinfo.id,
					"填写回执单",{
						shadeClose: false,
						shade: false,
						maxmin: false,
						moveOut: false,
						scrollbars:false,
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){

							location.reload();
						},
					});
			}).on('click','.btn-assist',function () {
				Fast.api.open("qingdongams/workorder/workorder/add_events?ids="+Config.idinfo.id,
					"邀请协作",{
						shadeClose: false,
						shade: false,
						maxmin: false,
						moveOut: false,
						scrollbars:false,
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
							location.reload();
						},
					});
			}).on('click','.btn-repair-result',function () {
				Fast.api.open("qingdongams/workorder/workorder/repair_result?ids="+Config.idinfo.id,
					"填写维修结果",{
						shadeClose: false,
						shade: false,
						maxmin: false,
						moveOut: false,
						scrollbars:false,
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){

							location.reload();
						},
					});
			}).on('click','.btn-enter-money',function () {
				Fast.api.open("qingdongams/workorder/workorder/enter_workorder_money?ids="+Config.idinfo.id,
					"录入费用",{
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){

							location.reload();
						},
					});
			}).on('click','.btn-discount',function () {
				Fast.api.open("qingdongams/workorder/workorder/edit_discount_money?ids="+Config.idinfo.id,
					"录入费用",{
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
							location.reload();
						},
					});
			}).on('click','.btn-pay-order',function () {
				Fast.api.open("qingdongams/workorder/workorder/pay_order?ids="+Config.idinfo.id,
					"去结算",{
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
						},
					});
			}).on('click','.btn-continue-repart',function () {
				var status=$(this).data('status');
				if(status == 1){
					Layer.confirm('确认要继续维修？', {
						btn: ['确定','取消'],
						title: '提示',
					},function(index, layero){
						Fast.api.ajax({
							url: "qingdongams/workorder/workorder/is_continue_test?is_continue=1&id="+Config.idinfo.id,
						},function(data,ret){
							if(ret.code == 1){
								Layer.close(index);
								location.reload();
							}
						},function(data,ret){
						});
					});
				}else{
					Layer.confirm('确认要取消维修？', {
						btn: ['确定','取消'],
						title: '提示',
					},function(index, layero){
						Fast.api.ajax({
							url: "qingdongams/workorder/workorder/is_continue_test?is_continue=9&id="+Config.idinfo.id,
						},function(data,ret){
							if(ret.code == 1){
								Layer.close(index);
								location.reload();
							}
						},function(data,ret){
						});
					});
				}
			}).on('click','.btn-complete-mobile',function () {
				Fast.api.open("qingdongams/workorder/workorder/complete_mobile?ids="+Config.idinfo.id,
					"完成工单",{
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
						},
					});
			}).on('click','.btn-edit',function () {
				Fast.api.open("qingdongams/workorder/workorder/edit?ids="+Config.idinfo.id,
					"编辑工单",{
						'area':[
							$(window).width() > 800 ? '90%' : '90%',
							$(window).height() > 600 ? '90%' : '90%'
						],
						callback:function(value){
							location.reload();
						},
					});
			}).on('click','.btn-assist-comment',function () {
				Fast.api.open("qingdongams/workorder/workorder/assits_comment?ids="+$(this).data('id'),
					"评论",{
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
						},
					});
			}).on('click','.btn-write',function () {
				Fast.api.open("qingdongams/workorder/workorder/add_progress?ids="+Config.idinfo.id,
					"填写异常分析",{
						'area':[
							$(window).width() > 800 ? '600px' : '400px',
							$(window).height() > 600 ? '500px' : '400px'
						],
						callback:function(value){
						},
					});
			});
			Controller.api.bindevent();
		},
		edit_discount_money    : function () {
			$('[name="row[is_charge]"]').on('click',function (){
				var is_charge=$('[name="row[is_charge]"]:checked').val();
				if(is_charge == 1){
					$('#discount_money').show();
				}else{
					$('#discount_money').hide();
				}
			})
			Controller.api.bindevent();
		},
		set_customer_product_number    : function () {
			Controller.api.bindevent();
		},
		repair_result    : function () {
			Controller.api.bindevent();
		},
		assits_comment    : function () {
			Controller.api.bindevent();
		},
		pay_order    : function () {
			Controller.api.bindevent();
		},
		add_progress    : function () {
			Controller.api.bindevent();
		},
		complete_mobile    : function () {
			$('[name="row[is_part]"]').on('click',function (){
				var is_part=$(this).val();
				if(is_part == 1){
					$('#use_parts').show();
				}else{
					$('#use_parts').hide();
				}
			});
			Controller.api.bindevent();
		},
		enter_workorder_money    : function () {

			//
			function setTotalMoney(){
				var total_money=0,parts_money=0;
				var wx_money=$('.wx_money').val();
				total_money=total_money+parseInt(wx_money);
				$('.use_parts').each(function (data,index){
					var is_charge=$(index).find('span').find('label').find('input[type="radio"]:checked').val();
					if(is_charge == 1){
						var price=$(index).data('price');
						price=parseInt(price);
						total_money=total_money+price;
						parts_money=parts_money+price;
					}
				});
				$('#total_money').val(total_money);
				$('#service_money').html(wx_money);
				$('#parts_money').html(parts_money);
			}
			$('.is_charge').on('click',function (){
				setTotalMoney();
			})
			$('.wx_money').on('change',function (){
				setTotalMoney();
			})
			setTotalMoney();
			Controller.api.bindevent();
		},
		get_event_template    : function () {

			Controller.api.bindevent();
		},
		set_team    : function () {
			$(document).on('click','.btn-zhidu',function () {
				$(this).parent().parent().find('.is_edit').html('只读')
				$(this).parent().parent().find('.staff_is_edit').val(0)
				$(this).parent().find('.btn-duxie').show()
				$(this).hide()
				layer.msg('权限更改为只读')
			})
			$(document).on('click','.btn-duxie',function () {
				$(this).parent().parent().find('.is_edit').html('读写')
				$(this).parent().parent().find('.staff_is_edit').val(1)
				$(this).parent().find('.btn-zhidu').show()
				$(this).hide()
				layer.msg('权限更改为读写')
			})
			$(document).on('click','.btn-delone',function () {
				$(this).parent().parent().remove()
			}).on('click','.btn-add_team',function () {
				var ids=$('#id').val();
				Fast.api.open("qingdongams/workorder/workorder/add_team?ids="+ids, '添加团队成员',{
					shadeClose: false,
					shade: false,
					maxmin: false,
					moveOut: false,
					scrollbars:false,
					'area':[
						$(window).width() > 800 ? '80%' : '80%',
						$(window).height() > 600 ? '80%' : '80%'
					],
					callback:function(value){
						if (value.is_edit == 1){
							var edit_html = '读写';
						}else{
							var edit_html = '只读';
						}

						var html = '<tr>\n' +
							'           <input type="hidden" name="row[staff][{$key+1}][id]" value="'+value.id+'"/>\n' +
							'           <input type="hidden" name="row[staff][{$key+1}][is_edit]" class="staff_is_edit" value="'+value.is_edit+'"/>\n' +
							'           <input type="hidden" name="row[staff][{$key+1}][roles]" value="2"/>\n' +
							'           <td class="text-center">'+value.name+'</td>\n' +
							'           <td class="text-center">'+value.post+'</td>\n' +
							'           <td class="text-center is_edit">'+edit_html+'</td>\n' +
							'           <td class="text-center">\n';
						if (value.is_edit == 1){
							html += '              <a class="btn btn-xs btn-info btn-zhidu">只读</a>\n' +
								'              <a class="btn btn-xs btn-info btn-duxie" style="display: none">读写</a>\n';
						}else{
							html += '              <a class="btn btn-xs btn-info btn-zhidu" style="display: none">只读</a>\n' +
								'              <a class="btn btn-xs btn-info btn-duxie">读写</a>\n';
						}

						html += '              <a href="javascript:;" class="btn btn-xs btn-danger btn-delone"   data-original-title="删除"><i class="fa fa-trash"></i></a>\n' +
							'           </td>\n' +
							'        </tr>';
						$('#table-team').append(html)
						Form.events.plupload("#plupload-local");
						//   在这里可以接收弹出层中使用`Fast.api.close(data)`进行回传数据
					},
				});
			})

			Controller.api.bindevent();
		},

		add_team    : function () {
			Form.api.bindevent($("form[role=form]"), function(data, ret){
				//这里是表单提交处理成功后的回调函数，接收来自php的返回数据
				Fast.api.close(data);//这里是重点
			});
		},
		api    : {
			bindevent : function () {

				$(document).on("fa.event.appendfieldlist", '.fieldlist', function(){
					//通用的表单组件事件绑定和组件渲染
					Form.events.selectpage($("form"));
					Form.events.datetimepicker($("form"));
					Form.events.plupload($("form"));
					$(".product").data("params", function (obj) {
						var customer_id=$('#c-customer_id').val();
						if(!customer_id){
							layer.alert('请先选择客户');
							return false;
						}
						return {customer_id: customer_id};
					});
					$(".customer_product").data("params", function (obj) {
						var customer_id=$('#c-customer_id').val();
						if(!customer_id){
							layer.alert('请先选择客户');
							return false;
						}
						return {customer_id: customer_id};
					});
				})
				.on("click", ".select-customer", function(){
					var $this=$(this);
					top.Fast.api.open($(this).data("url") , __('Select'), {callback: function (data) {
							$this.html(data.name);
							$('[name="'+$this.data('name')+'"]').val(data.id);
						},area:["100%", "100%"]});
				}).on("click", ".select-parts", function(){
					var $this=$(this);
					top.Fast.api.open($(this).data("url") , __('Select'), {callback: function (data) {
							$this.html(data.name);
							$('[name="'+$this.data('name')+'"]').val(data.id);

							$(".fieldlist input:eq(0)").trigger("change");
							$(".fieldlist:eq(1) input:eq(0)").trigger("change");
						},area:["100%", "100%"]});
				}).on("click", ".select-product", function(){
					var $this=$(this),customer_id=$('[name="row[customer_id]"]').val();
					if(!customer_id){
						Layer.msg('请先选择客户');
						return false;
					}
					top.Fast.api.open($(this).data("url")+"&customer_id="+customer_id, __('Select'), {callback: function (data) {
							$this.html(data.product.name);
							$('[name="'+$this.data('name')+'"]').val(data.id);

							$(".fieldlist input:eq(0)").trigger("change");
						},area:["100%", "100%"]});
				}).on("click", ".select-contacts", function(){
					var $this=$(this),customer_id=$('[name="row[customer_id]"]').val();
					if(!customer_id){
						Layer.msg('请先选择客户');
						return false;
					}
					top.Fast.api.open($(this).data("url")+"&customer_id="+customer_id, __('Select'), {callback: function (data) {
							$this.html(data.name);
							$('[name="'+$this.data('name')+'"]').val(data.id);

							$(".fieldlist input:eq(2)").trigger("change");
						},area:["100%", "100%"]});
				});
				$("#c-contacts").data("params", function (obj) {
					var customer_id=$('#c-customer_id').val();
					return {customer_id: customer_id};
				});



				Form.api.bindevent($("form[role=form]"), function(data, ret){
					get_need_number()
					//这里是表单提交处理成功后的回调函数，接收来自php的返回数据
					Fast.api.close(data);//这里是重点
					window.location.reload();
				}, function(data, ret){
				},function (){
					$(".fieldlist input:eq(0)").trigger("change");

				});
			}
		}
	};
	return Controller;
});